package cz.acies.genea.data.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.QueryRunner;

import cz.acies.data.DBConnector;
import cz.acies.data.dao.DefaultDAO;
import cz.acies.data.dao.DefaultMapListHandler;
import cz.acies.data.dao.DefaultRowProcessor;
import cz.acies.genea.data.persist.GedPerson;
import cz.acies.uniql.sql.SelectQuery;
import cz.acies.uniql.sql.element.UniQLCondition;
import cz.acies.uniql.sql.element.UniQLWhere;

public class GedChildrenDAO extends DefaultDAO
{
	public List<GedPerson> selevtByParentId(String is)  {
		List<GedPerson> data = new ArrayList<GedPerson>();
		try {
			SelectQuery sql = new SelectQuery(dbmd())
				.addFrom("chikdren")
				.add(new UniQLCondition("chikdren.parentId", "=", "'"+is+"'"));
			
			QueryRunner qr = new QueryRunner(DBConnector.instance().getDataSource());
			List<Map<String, Object>> list = qr.query(sql.toSQLString(), new DefaultMapListHandler(new DefaultRowProcessor()));
			
			
		} catch (Exception exc) {
			exc.printStackTrace();
		}
		return data;
	}

	public List<GedPerson> selevtByWhere(UniQLWhere where)  {
		List<GedPerson> data = new ArrayList<GedPerson>();
		try {
			SelectQuery sql = new SelectQuery(dbmd()).addFrom("chikdren").addWhere(where);
			QueryRunner qr = new QueryRunner(DBConnector.instance().getDataSource());
			List<Map<String, Object>> list = qr.query(sql.toSQLString(), new DefaultMapListHandler(new DefaultRowProcessor()));
			
			
		} catch (Exception exc) {
			exc.printStackTrace();
		}
		return data;
	}
	
	
}
